package com.yidu.boss.sys.service.impl;

import com.yidu.boss.sys.dao.ExchangeMapper;
import com.yidu.boss.sys.domain.Exchange;
import com.yidu.boss.sys.domain.ExchangeExample;
import com.yidu.boss.sys.service.ExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ExchangeServiceImpl implements ExchangeService {

    @Autowired
    private ExchangeMapper exchangeMapper;

    /**
     * 查询所有
     * @param exchangeExample
     * @return
     */
    @Override
    public List<Exchange> selectByExample(ExchangeExample exchangeExample) {
        return exchangeMapper.selectByExample(exchangeExample);
    }
    /**
     * 模糊查询
     *
     * @param exchange
     * @return
     */
    public List<Exchange> selectLike(String exchange) {
        ExchangeExample exchangeExample = new ExchangeExample();
        //模糊查询名字
        exchangeExample.or().andExchangeNameLike(exchange);
        //集合
        List<Exchange> exchangeList = exchangeMapper.selectByExample(exchangeExample);
        return exchangeList;
    }

    /**
     * 模糊查询所有
     * @param condition
     * @return
     */
    @Override
    public List<Exchange> selectSomeByMore(String condition) {
        //调用业务层模糊查询所有的方法
        List<Exchange> exchangeList = exchangeMapper.selectSomeByMore(condition);
        return exchangeList;
    }
    /**
     * 添加
     * @param exchange
     * @return
     */
    @Override
    public int insertExchange(Exchange exchange) {
        //Id
        exchange.setExchangeId(UUID.randomUUID().toString().substring(0,6).replace("-",""));
        System.out.println("exchange = " + exchange);
        int i = exchangeMapper.insertSelective(exchange);
        return i;
    }
    /**
     * 修改
     * @param exchange
     * @return
     */
    @Override
    public int updateExchange(Exchange exchange) {
        //Example类
        ExchangeExample exchangeExample =new ExchangeExample();
        //获得Id
        exchangeExample.or().andExchangeIdEqualTo(exchange.getExchangeId());
        int i =exchangeMapper.updateByExampleSelective(exchange,exchangeExample);
        return i;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteExchange(String id) {
        int i =exchangeMapper.deleteByPrimaryKey(id);
        System.err.println("i = " + i);
        return i;
    }

}
